<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
class PHPExcel_Writer_Excel5_Xf
{
    private $isStyleXf;
    private $fontIndex;
    private $numberFormatIndex;
    private $textJustLast;
    private $foregroundColor;
    private $backgroundColor;
    private $bottomBorderColor;
    private $topBorderColor;
    private $leftBorderColor;
    private $rightBorderColor;
    private static $mapBorderStyles;
    private static $mapFillTypes;
    private static $mapHAlignments;
    private static $mapVAlignments;
    public function __construct(PHPExcel_Style $style = NULL)
    {
        $this->isStyleXf = false;
        $this->fontIndex = 0;
        $this->numberFormatIndex = 0;
        $this->textJustLast = 0;
        $this->foregroundColor = 64;
        $this->backgroundColor = 65;
        $this->_diag = 0;
        $this->bottomBorderColor = 64;
        $this->topBorderColor = 64;
        $this->leftBorderColor = 64;
        $this->rightBorderColor = 64;
        $this->_diag_color = 64;
        $this->_style = $style;
    }
    public function writeXf()
    {
        if($this->isStyleXf) {
            $style = 65525;
        } else {
            $style = self::mapLocked($this->_style->getProtection()->getLocked());
            $style |= self::mapHidden($this->_style->getProtection()->getHidden()) << 1;
        }
        $atr_num = $this->numberFormatIndex != 0 ? 1 : 0;
        $atr_fnt = $this->fontIndex != 0 ? 1 : 0;
        $atr_alc = (int) $this->_style->getAlignment()->getWrapText() ? 1 : 0;
        $atr_bdr = self::mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) || self::mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) || self::mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) || self::mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) ? 1 : 0;
        $atr_pat = $this->foregroundColor != 64 || $this->backgroundColor != 65 || self::mapFillType($this->_style->getFill()->getFillType()) ? 1 : 0;
        $atr_prot = self::mapLocked($this->_style->getProtection()->getLocked()) | self::mapHidden($this->_style->getProtection()->getHidden());
        if(self::mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) == 0) {
            $this->bottomBorderColor = 0;
        }
        if(self::mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) == 0) {
            $this->topBorderColor = 0;
        }
        if(self::mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) == 0) {
            $this->rightBorderColor = 0;
        }
        if(self::mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) == 0) {
            $this->leftBorderColor = 0;
        }
        if(self::mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle()) == 0) {
            $this->_diag_color = 0;
        }
        $record = 224;
        $length = 20;
        $ifnt = $this->fontIndex;
        $ifmt = $this->numberFormatIndex;
        $align = $this->mapHAlign($this->_style->getAlignment()->getHorizontal());
        $align |= (int) $this->_style->getAlignment()->getWrapText() << 3;
        $align |= self::mapVAlign($this->_style->getAlignment()->getVertical()) << 4;
        $align |= $this->textJustLast << 7;
        $used_attrib = $atr_num << 2;
        $used_attrib |= $atr_fnt << 3;
        $used_attrib |= $atr_alc << 4;
        $used_attrib |= $atr_bdr << 5;
        $used_attrib |= $atr_pat << 6;
        $used_attrib |= $atr_prot << 7;
        $icv = $this->foregroundColor;
        $icv |= $this->backgroundColor << 7;
        $border1 = self::mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle());
        $border1 |= self::mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) << 4;
        $border1 |= self::mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) << 8;
        $border1 |= self::mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) << 12;
        $border1 |= $this->leftBorderColor << 16;
        $border1 |= $this->rightBorderColor << 23;
        $diagonalDirection = $this->_style->getBorders()->getDiagonalDirection();
        $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH or $diag_tl_to_rb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH || $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_DOWN;
        $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH or $diag_tr_to_lb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH || $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_UP;
        $border1 |= $diag_tl_to_rb << 30;
        $border1 |= $diag_tr_to_lb << 31;
        $border2 = $this->topBorderColor;
        $border2 |= $this->bottomBorderColor << 7;
        $border2 |= $this->_diag_color << 14;
        $border2 |= self::mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle()) << 21;
        $border2 |= self::mapFillType($this->_style->getFill()->getFillType()) << 26;
        $header = pack("vv", $record, $length);
        $biff8_options = $this->_style->getAlignment()->getIndent();
        $biff8_options |= (int) $this->_style->getAlignment()->getShrinkToFit() << 4;
        $data = pack("vvvC", $ifnt, $ifmt, $style, $align);
        $data .= pack("CCC", self::mapTextRotation($this->_style->getAlignment()->getTextRotation()), $biff8_options, $used_attrib);
        $data .= pack("VVv", $border1, $border2, $icv);
        return $header . $data;
    }
    public function setIsStyleXf($value)
    {
        $this->isStyleXf = $value;
    }
    public function setBottomColor($colorIndex)
    {
        $this->bottomBorderColor = $colorIndex;
    }
    public function setTopColor($colorIndex)
    {
        $this->topBorderColor = $colorIndex;
    }
    public function setLeftColor($colorIndex)
    {
        $this->leftBorderColor = $colorIndex;
    }
    public function setRightColor($colorIndex)
    {
        $this->rightBorderColor = $colorIndex;
    }
    public function setDiagColor($colorIndex)
    {
        $this->_diag_color = $colorIndex;
    }
    public function setFgColor($colorIndex)
    {
        $this->foregroundColor = $colorIndex;
    }
    public function setBgColor($colorIndex)
    {
        $this->backgroundColor = $colorIndex;
    }
    public function setNumberFormatIndex($numberFormatIndex)
    {
        $this->numberFormatIndex = $numberFormatIndex;
    }
    public function setFontIndex($value)
    {
        $this->fontIndex = $value;
    }
    private static function mapBorderStyle($borderStyle)
    {
        if(isset(self::$mapBorderStyles[$borderStyle])) {
            return self::$mapBorderStyles[$borderStyle];
        }
        return 0;
    }
    private static function mapFillType($fillType)
    {
        if(isset(self::$mapFillTypes[$fillType])) {
            return self::$mapFillTypes[$fillType];
        }
        return 0;
    }
    private function mapHAlign($hAlign)
    {
        if(isset(self::$mapHAlignments[$hAlign])) {
            return self::$mapHAlignments[$hAlign];
        }
        return 0;
    }
    private static function mapVAlign($vAlign)
    {
        if(isset(self::$mapVAlignments[$vAlign])) {
            return self::$mapVAlignments[$vAlign];
        }
        return 2;
    }
    private static function mapTextRotation($textRotation)
    {
        if(0 <= $textRotation) {
            return $textRotation;
        }
        if($textRotation == -165) {
            return 255;
        }
        if($textRotation < 0) {
            return 90 - $textRotation;
        }
    }
    private static function mapLocked($locked)
    {
        switch ($locked) {
            case PHPExcel_Style_Protection::PROTECTION_INHERIT:
                return 1;
                break;
            case PHPExcel_Style_Protection::PROTECTION_PROTECTED:
                return 1;
                break;
            case PHPExcel_Style_Protection::PROTECTION_UNPROTECTED:
                return 0;
                break;
            default:
                return 1;
        }
    }
    private static function mapHidden($hidden)
    {
        switch ($hidden) {
            case PHPExcel_Style_Protection::PROTECTION_INHERIT:
                return 0;
                break;
            case PHPExcel_Style_Protection::PROTECTION_PROTECTED:
                return 1;
                break;
            case PHPExcel_Style_Protection::PROTECTION_UNPROTECTED:
                return 0;
                break;
            default:
                return 0;
        }
    }
}

?>